package com.thon.controller.rest;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.thon.entity.project.ProjectAd;
import com.thon.service.project.ProjectAdService;

@Controller
@RequestMapping(value="/api/project/ad")
public class ProjectAdRestConttroller {

	@Autowired
	private ProjectAdService projectAdService;

	/**
	 * 添加公告接口方法
	 * @param projectAd 公告实体
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public ResponseEntity<HttpEntity> addProjectAd(
		@RequestBody ProjectAd projectAd
		){		
		projectAd.setCreatedDate(new Date());
		projectAdService.add(projectAd);
		return new ResponseEntity(HttpStatus.CREATED);		
	}
	/**
	 * 获取最近公告
	 * @param projectId 项目Id
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping(value="/get",method=RequestMethod.GET)
	public ResponseEntity<HttpEntity> getProjectAd(
			@RequestParam(value="pid") Integer projectId
			){
		ProjectAd projectAd=projectAdService.getProjectAdByNow(projectId);
		return new ResponseEntity(projectAd,HttpStatus.OK);
	}
}
